home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.09 Sep 89 / MacApp Code / Plot - Nelson / FieldToStringProc next >
Encoding:
Text File  |  1988-11-20  |  2.7 KB  |  79 lines  |  [TEXT/MPS ]

  1.  
  2. {=================== Global FieldToString Procedure ==================}
  3.  
  4. { This procedure will allow your fields procedure to display all of   }
  5. { the types defined by the SANE unit.  The type constants are:        }
  6. {      bReal , bSingle - for Pascal Real and SANE Single type         }
  7. {      bDouble         - for SANE Double type                         }
  8. {      bExtended       - for SANE Extended type                       }
  9. {                                                                     }
  10. { Be sure to place the MyFieldToString routine in a RESIDENT Segment. }
  11. { (One that is never unloaded.)                                       }
  12. {                                                                     }
  13. { Also place the following line in your IApplication method:          }
  14. {                                                                     }
  15. {   gFieldToStrRtn := @MyFieldToString;                               }
  16.  
  17.  
  18. {$IFC qDebug}
  19. {$IFC qTrace} {$D+} {$ENDC}
  20.  
  21. PROCEDURE MyFieldToString(theData: Ptr;
  22.                           fieldType: integer;
  23.                           VAR theString: str255);
  24.                                   
  25.     CONSTANT
  26.         DecPrec = 2;  { Change this if you want more decimal precision }
  27.  
  28.    TYPE
  29.       TAlias              = RECORD
  30.          CASE integer OF
  31.             bReal, bSingle:
  32.                (asReal             : Real);
  33.             bDouble:
  34.                (asDouble           : Double);
  35.             bExtended:
  36.                (asExtended         : Extended);
  37.          END;
  38.  
  39.    VAR
  40.       alias              : ^TAlias;
  41.       aDecForm           : DecForm;
  42.       x                  : Extended;
  43.       NumStr             : DecStr;
  44.  
  45.    BEGIN
  46.       alias := Pointer(theData);
  47.       WITH alias^ DO
  48.          CASE fieldType OF
  49.             bReal, bSingle:
  50.                BEGIN
  51.                   aDecForm.style := FixedDecimal;
  52.                   aDecForm.digits := DecPrec;
  53.                   x := asReal;
  54.                   Num2Str(aDecForm, x, NumStr);
  55.                   theString := str255(NumStr);
  56.                END;
  57.             bDouble:
  58.                BEGIN
  59.                   aDecForm.style := FixedDecimal;
  60.                   aDecForm.digits := DecPrec;
  61.                   x := asDouble;
  62.                   Num2Str(aDecForm, x, NumStr);
  63.                   theString := str255(NumStr);
  64.                END;
  65.             bExtended:
  66.                BEGIN
  67.                   aDecForm.style := FixedDecimal;
  68.                   aDecForm.digits := DecPrec;
  69.                   x := asExtended;
  70.                   Num2Str(aDecForm, x, NumStr);
  71.                   theString := str255(NumStr);
  72.                END;
  73.             OTHERWISE StdFieldToString(theData, fieldType, theString);
  74.          END;
  75.    END;
  76.  
  77. {$IFC qTrace} {$D++} {$ENDC}
  78. {$ENDC qDebug}
  79.